import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mahjong/const/MahjongConst.dart';
import 'package:mahjong/const/MahjongSystemConst.dart';
import 'package:mahjong/entity/mahjong/MahjongInfoEntity.dart';
import 'package:provider/provider.dart';

class SwapMahjongWidget extends StatelessWidget {
  final bool swap;
  final UserPosition position;
  const SwapMahjongWidget({Key key, this.swap, this.position})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Consumer(builder: (BuildContext buildContext,
        MahjongInfoEntity roomProvider, Widget child) {
      if (roomProvider.state != RoomState.CHANGE || !swap) {
        return Container();
      }
      switch (position) {
        case UserPosition.RIGHT:
          return Positioned(
              bottom: ScreenUtil().screenHeight / 2 -
                  MahjongSystemConst.btSwapCardWidth * 3 / 2,
              left: ScreenUtil().screenWidth / 2 +
                  MahjongSystemConst.exportAreaSize / 2,
              child: Container(
                  width: MahjongSystemConst.btSwapCardWidth *
                      MahjongSystemConst.cardWHScale,
                  height: MahjongSystemConst.btSwapCardWidth * 3,
                  child: Stack(
                    children: [
                      Positioned(
                        top: 0,
                        child: Image.asset(
                          "images/mahjong/commons/bg_p1_oper_b.png",
                          fit: BoxFit.fill,
                          height: MahjongSystemConst.btSwapCardWidth,
                        ),
                      ),
                      Positioned(
                        top: MahjongSystemConst.btSwapCardWidth * 0.8,
                        child: Image.asset(
                          "images/mahjong/commons/bg_p1_oper_b.png",
                          fit: BoxFit.fill,
                          height: MahjongSystemConst.btSwapCardWidth,
                        ),
                      ),
                      Positioned(
                        top: MahjongSystemConst.btSwapCardWidth * 2 * 0.8,
                        child: Image.asset(
                          "images/mahjong/commons/bg_p1_oper_b.png",
                          fit: BoxFit.fill,
                          height: MahjongSystemConst.btSwapCardWidth,
                        ),
                      ),
                    ],
                  )));
          break;
        case UserPosition.LEFT:
          return Positioned(
              bottom: ScreenUtil().screenHeight / 2 -
                  MahjongSystemConst.btSwapCardWidth * 3 / 2,
              right: ScreenUtil().screenWidth / 2 +
                  MahjongSystemConst.exportAreaSize / 2,
              child: Container(
                  width: MahjongSystemConst.btSwapCardWidth *
                      MahjongSystemConst.cardWHScale,
                  height: MahjongSystemConst.btSwapCardWidth * 3,
                  child: Stack(
                    children: [
                      Positioned(
                        top: 0,
                        child: Image.asset(
                          "images/mahjong/commons/bg_p1_oper_b.png",
                          fit: BoxFit.fill,
                          height: MahjongSystemConst.btSwapCardWidth,
                        ),
                      ),
                      Positioned(
                        top: MahjongSystemConst.btSwapCardWidth * 0.8,
                        child: Image.asset(
                          "images/mahjong/commons/bg_p1_oper_b.png",
                          fit: BoxFit.fill,
                          height: MahjongSystemConst.btSwapCardWidth,
                        ),
                      ),
                      Positioned(
                        top: MahjongSystemConst.btSwapCardWidth * 2 * 0.8,
                        child: Image.asset(
                          "images/mahjong/commons/bg_p1_oper_b.png",
                          fit: BoxFit.fill,
                          height: MahjongSystemConst.btSwapCardWidth,
                        ),
                      ),
                    ],
                  )));
          break;
        case UserPosition.TOP:
          return Positioned(
              bottom: ScreenUtil().screenHeight / 2 +
                  MahjongSystemConst.exportAreaSize / 2,
              left: ScreenUtil().screenWidth / 2 -
                  MahjongSystemConst.btSwapCardWidth * 3 / 2,
              child: Container(
                width: MahjongSystemConst.btSwapCardWidth * 3,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset(
                      "images/mahjong/user/bottom/EXCHANGE_CARD.png",
                      width: MahjongSystemConst.btSwapCardWidth,
                    ),
                    Image.asset(
                      "images/mahjong/user/bottom/EXCHANGE_CARD.png",
                      width: MahjongSystemConst.btSwapCardWidth,
                    ),
                    Image.asset(
                      "images/mahjong/user/bottom/EXCHANGE_CARD.png",
                      width: MahjongSystemConst.btSwapCardWidth,
                    ),
                  ],
                ),
              ));
          break;
        case UserPosition.BOTTOM:
          return Positioned(
              top: ScreenUtil().screenHeight / 2 +
                  MahjongSystemConst.exportAreaSize / 2,
              left: ScreenUtil().screenWidth / 2 -
                  MahjongSystemConst.btSwapCardWidth * 3 / 2,
              child: Container(
                width: MahjongSystemConst.btSwapCardWidth * 3,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset(
                      "images/mahjong/user/bottom/EXCHANGE_CARD.png",
                      width: MahjongSystemConst.btSwapCardWidth,
                    ),
                    Image.asset(
                      "images/mahjong/user/bottom/EXCHANGE_CARD.png",
                      width: MahjongSystemConst.btSwapCardWidth,
                    ),
                    Image.asset(
                      "images/mahjong/user/bottom/EXCHANGE_CARD.png",
                      width: MahjongSystemConst.btSwapCardWidth,
                    ),
                  ],
                ),
              ));
          break;
        default:
          return Container();
      }
    });
  }
}
